//package com.etc.common;
//
//import java.util.List;
//
//import javax.validation.Valid;
//import javax.validation.constraints.NotNull;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.http.converter.HttpMessageConversionException;
//import org.springframework.validation.BindingResult;
//import org.springframework.validation.FieldError;
//import org.springframework.validation.ObjectError;
//import org.springframework.web.bind.MethodArgumentNotValidException;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.bind.annotation.RestControllerAdvice;
//
///**
// *
// * Filename:    GlobalExceptionHandler.java
// * Description:  异常统一处理类
// * 开发时关闭
// * Copyright:   Copyright (c) 2018-2019 All Rights Reserved.
// * Company:     chinasofti.com Inc.
// * @author:     mazheng
// * @version:    1.0
// * Create at:   2020年3月3日 下午3:06:47
// *
// * Modification History:
// * Date         Author      Version     Description
// * ------------------------------------------------------------------
// * 2020年3月3日      mazheng      1.0         1.0 Version
// *
// */
//@RestControllerAdvice
//public class GlobalExceptionHandler {
////    private static Logger LOGGER = LoggerFactory.getLogger(GlobalExceptionHandler.class);
////
////
////    public GlobalExceptionHandler() {
////    }
////    /**
////     * 校验错误拦截处理
////     * 处理{@link Valid} & {@link NotNull}
////     *
////     * @param exception 错误信息集合
////     * @return 错误信息
////     */
////    @ExceptionHandler(MethodArgumentNotValidException.class)
////    public CodeMessage validationBodyException(MethodArgumentNotValidException exception) {
////        BindingResult result = exception.getBindingResult();
////        if (result.hasErrors()) {
////            List<ObjectError> errors = result.getAllErrors();
////            errors.forEach(p -> {
////                FieldError fieldError = (FieldError) p;
////                LOGGER.warn("Data check failure : object={}, field={}, errorMessage={}", fieldError.getObjectName(), fieldError.getField(), fieldError.getDefaultMessage());
////            });
////            return CodeMessage.faild(Code.FAIL,
////                    result.getFieldError() == null ? "请求参数有误" : result.getFieldError().getDefaultMessage());
////        }
////        //其他错误
////        return CodeMessage.faild(Code.ERROR, "请联系管理员");
////    }
////
////
////    /**
////     * 参数类型转换错误 {@link HttpMessageConversionException}
////     *
////     * @param exception 错误
////     * @return 错误信息
////     */
////    @ExceptionHandler(HttpMessageConversionException.class)
////    public CodeMessage parameterTypeException(HttpMessageConversionException exception) {
////        LOGGER.warn("parameterTypeException {}", exception.getCause().getLocalizedMessage());
////        return CodeMessage.faild(Code.FAIL, "请求参数类型有误");
////    }
////
////
////    @ExceptionHandler(value = ServiceException.class)
////    @ResponseBody
////    public CodeMessage baseErrorHandler(ServiceException e) throws Exception {
////        CodeMessage r = new CodeMessage();
////        r.setMsg(e.getMessage());
////        r.setCode(e.getCode());
////        return r;
////    }
////
////  @ExceptionHandler(value = Exception.class)
////  @ResponseBody
////  public CodeMessage exceptionErrorHandler(Exception e) throws Exception {
////      CodeMessage r = new CodeMessage();
////      r.setMsg(e.getMessage());
////      r.setCode(Code.FAIL);
////      return r;
////  }
//  @ExceptionHandler(value = ServiceException.class)
//  @ResponseBody
//  public CodeMessage exceptionErrorHandler(ServiceException e) throws Exception {
//      CodeMessage r = new CodeMessage();
//      r.setMsg(e.getMessage());
//       if (e.getMessage().equals(Code.ERROR)) {
//          r.setCode(Code.ERROR);
//          r.setMsg("系统异常，联系管理员");
//      }
//
//      return r;
//  }
//
//
//
//}
